package com.yonyou.brigade.third_parties.didi.controller;

import com.yonyou.brigade.basic_init.enums.ChannelEnum;
import com.yonyou.brigade.basic_init.service.IBriChannelService;
import com.yonyou.brigade.third_parties.didi.model.DiDiConfig;
import com.yonyou.brigade.third_parties.didi.service.IDiDiOrderService;
import com.yonyou.ybzboot.starter.common.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 订单操作 controller
 *
 * @author kangfw5
 */
@RestController
@RequestMapping("/third/didi/order")
public class DiDiOrderController {
    @Autowired
    private IDiDiOrderService diDiOrderService;

    @Autowired
    private IBriChannelService briChannelService;

    /**
     * 获取个人订单
     *
     * @param tenantId 租户ID
     * @param orgPk    组织PK
     * @param phone    手机号
     * @param start    开始时间
     * @param end      结束时间
     * @param payType  支付方式
     * @return
     */
    @RequestMapping(value = "/getPersonOrder", method = RequestMethod.GET)
    public List getPersonOrder(String tenantId, String orgPk, String phone, String start, String end, Integer payType) {
        DiDiConfig didiConfig = (DiDiConfig) briChannelService.getChannelConfig(tenantId, ChannelEnum.DIDI.getName(), new DiDiConfig());
        if (didiConfig == null) {
            throw new BusinessException("获取该租户滴滴企业版开通信息失败");
        }
        return diDiOrderService.queryDiDiOrderWithDate(start, end, payType, didiConfig, phone);
    }

    /**
     * 获取个人订单页TOKEN
     *
     * @param tenantId 租户ID
     * @param orgPk    组织PK
     * @param phone    手机号
     * @return
     */
    @RequestMapping(value = "getOrderPage", method = RequestMethod.GET)
    public String getOrderPage(String tenantId, String orgPk, String phone) {
        DiDiConfig didiConfig = (DiDiConfig) briChannelService.getChannelConfig(tenantId, ChannelEnum.DIDI.getName(), new DiDiConfig());
        if (didiConfig == null) {
            throw new BusinessException("获取该租户滴滴企业版开通信息失败");
        }
        return diDiOrderService.getPersonOrderPage(didiConfig, phone);
    }
}
